#!/usr/bin/env python
# Create: 2018/10/22
__author__ = '749B'
"""gevent + requests"""

from bs4 import BeautifulSoup
import gevent
from gevent import monkey
monkey.patch_all()  # 必须放在requests模块导入前
import requests

url_list = [
    'https://github.com/explore',
    'https://www.djangoproject.com/',
    'http://www.python-requests.org/en/master/',
    'https://jquery.com/',
    'https://getbootstrap.com/',
    'https://www.solarwinds.com/',
    'https://www.zabbix.com/',
    'http://open-falcon.org/',
    'https://www.python.org/',
    'http://www.jetbrains.com/',
]


def fetch_request(url):
    r = requests.get(url)
    r.encoding = 'utf-8'
    soup = BeautifulSoup(r.text, features='html.parser')
    title = soup.find('title')
    print(title)


if __name__ == '__main__':
    g_list = []
    for url in url_list:
        g_list.append(gevent.spawn(fetch_request, url=url))
    gevent.joinall(g_list)


